#ifndef PARSER_H
#define PARSER_H

#include <string>
#include "stringtokenizer.h"
#include "matcher.h"
#include "spa_types.h"
#include "TNode.h"
#include <vector>
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

class Parser
{
private:
	STRING codeList;
	int statementCount;
	Matcher matcher;
	StringTokenizer tokenizer;
	STRING errorMsg;
	queue<string> callValidator;
	//vector<TNode*> roots;
public:
	Parser();
	bool parse(string str);
	bool runParser();
	TNode* createProcedure();
	TNode* createStatementList(TNode* parentNode,int nchild);
	TNode* createStatement(string previousToken,TNode* parentNode,int nchild);
	TNode* createWhile(TNode* parentNode,int nchild);
	TNode* createIf(TNode* parentNode, int nchild);
	TNode* createAssign(string previousToken,TNode* parentNode,int nchild);
	TNode* createExpression();
	TNode* createExpressionV2(TNode* parentNode);
	TNode* createCall(TNode* parentNode, int nchild);
	STRING getErrorMsg();
	void recreateCode();
	void displayProcedure(TNode* node);
	void displayStatementList(TNode* node);
	void displayStatement(TNode* node);
	void displayWhile(TNode* node);
	void displayAssignment(TNode* node);
	void displayExpression(TNode* node);
	STRING getCodeList();
	~Parser();
};

#endif